//------------------------------------------------------------------------------
// <copyright file="AbstractItem.cs" company="Damian Antonowicz">
//       copyright © 2010 Damian Antonowicz
// </copyright>
// <author>Damian Antonowicz</author>
// <email>poczta@damianantonowicz.pl</email>
//------------------------------------------------------------------------------

using System;
using System.Xml.Serialization;
using System.IO;
using System.ComponentModel;
using DAnton.Utilities.Helpers;

namespace DotBeer.Business.Entities
{
    public abstract class AbstractItem : INotifyPropertyChanged
    {
        #region private properties

        protected string name;
        protected bool costSpecified,
                       recipeCostSpecified,
                       urlSpecified;

        #endregion

        #region public properties

        public abstract string Name 
        { 
            get; 
            set; 
        }

        public abstract string Url
        {
            get;
            set;
        }

        [XmlIgnore]
        public bool UrlSpecified
        {
            get { return this.urlSpecified; }
        }

        [XmlIgnore]
        public abstract int TotalCost
        {
            get;
        }

        [XmlIgnore]
        public bool CostSpecified
        {
            get { return this.costSpecified; }
        }

        public abstract int Cost
        {
            get;
            set;
        }

        [XmlIgnore]
        public bool RecipeCostSpecified
        {
            get { return this.recipeCostSpecified; }
        }

        public abstract int RecipeCost
        {
            get;
            set;
        }

        [XmlIgnore]
        public string ImagePath
        {
            get { return this.GetImagePath(); }
            set { this.SetImage(value); }
        }

        #endregion

        #region public methods

        public override string ToString()
        {
            return String.Format("{0}", this.name);
        }

        #endregion

        #region private methods

        private string GetImagePath()
        {
            return String.Format("{0}Images\\Items\\{1}.gif", IOHelper.ApplicationStartupPath, this.name);
        }

        private void SetImage(string newFileName)
        {
            if (File.Exists(this.GetImagePath()))
                File.Delete(this.GetImagePath());

            File.Copy(newFileName, this.GetImagePath());
            OnPropertyChanged("ImagePath");
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Notify that property was changed.
        /// </summary>
        /// <param this.name="info">Changed property this.name</param>
        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

        #endregion
    }
}
